Pytest
Table of Content
Test#
- Arrange (setup)
- Act (object/method under test)
- Assert
- Cleanup
Groping Tests#
Custom markers#
- Using
pytest.markdecorator we can group tests
Idea for custom marker
- sanity
- regression
import pytest
@pytest.mark.g1
def test_demo():
assert True
python -m pytest -m g1 g2
Builtin markers#
pytest --markers
...
@pytest.mark.skip(reason=None)
@pytest.mark.skipif(condition, ..., *, reason=...)
@pytest.mark.xfail(condition, ..., *, reason=..., run=True, raises=None, strict=xfail_strict)
...
xfail#
mark the test function as an expected failure